#include <vector>
#include <string>
#include <fstream>
#include <iostream>

using namespace std;

const int IMAGE_THEME_COUNT = 143;

vector<string> image1;
vector<string> image2;
vector<int> choice;
vector<string> themes;
bool empty[IMAGE_THEME_COUNT];

int main(int argc, const char *argv[])
{
    ifstream fin1("image_theme_list");
    ifstream fin2("image_theme_list_stop_words_removed_with_blank");
    ifstream fin3("music_theme_choice");
    ifstream fin4("all_music_themes");
    ofstream fout("image_music");

    string word;
    int id;
    while (getline(fin1, word)) {
        image1.push_back(word); 
    }
    int cnt = 0;
    while (getline(fin2, word)) {
        image2.push_back(word);
        if (word.empty()) {
            empty[cnt] = true;   
        }
        ++cnt;
    }
    while (fin3 >> id) {
        choice.push_back(id); 
    }
    while (getline(fin4, word)) {
        themes.push_back(word);
    }
    
    cnt = 0;
    for (int i = 0; i < IMAGE_THEME_COUNT; ++i) {
        if (!empty[i]) {
            fout << image1[i] << ' ' << themes[choice[cnt] - 1] << endl;
            ++cnt;   
        }   
    }


    return 0;
}
